home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
ARPSUBR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-14
|
2KB
|
71 lines
/* Address Resolution Protocol (ARP) low-level functions
*/
#include "global.h"
#include "mbuf.h"
#include "timer.h"
#include "iface.h"
#include "enet.h"
#include "ax25.h"
#include "arp.h"
/* Copy a host format arp structure into mbuf for transmission */
struct mbuf *
htonarp(arp)
register struct arp *arp;
{
struct mbuf *bp;
register char *buf;
char addrbuf[4];
if(arp == (struct arp *)NULL)
return NULLBUF;
if((bp = alloc_mbuf(16 + 2 * arp->hwalen)) == NULLBUF)
return NULLBUF;
buf = bp->data;
buf = put16(buf,arp->hardware);
buf = put16(buf,arp->protocol);
*buf++ = arp->hwalen;
*buf++ = arp->pralen;
buf = put16(buf,arp->opcode);
memcpy(buf,arp->shwaddr,(int16)uchar(arp->hwalen));
buf += arp->hwalen;
put32(addrbuf,arp->sprotaddr);
memcpy(buf,addrbuf,4);
buf += 4;
memcpy(buf,arp->thwaddr,(int16)uchar(arp->hwalen));
buf += arp->hwalen;
put32(addrbuf,arp->tprotaddr);
memcpy(buf,addrbuf,4);
buf += 4;
bp->cnt = buf - bp->data;
return bp;
}
/* Convert an incoming ARP packet into a host-format structure */
int
ntoharp(arp,bpp)
register struct arp *arp;
struct mbuf **bpp;
{
if(arp == (struct arp *)NULL || bpp == NULLBUFP)
return -1;
arp->hardware = pull16(bpp);
arp->protocol = pull16(bpp);
arp->hwalen = pullchar(bpp);
arp->pralen = pullchar(bpp);
arp->opcode = pull16(bpp);
pullup(bpp,arp->shwaddr,(int16)uchar(arp->hwalen));
arp->sprotaddr = pull32(bpp);
pullup(bpp,arp->thwaddr,(int16)uchar(arp->hwalen));
arp->tprotaddr = pull32(bpp);
/* Get rid of anything left over */
free_p(*bpp);
*bpp = NULLBUF;
return 0;
}